/**
 * 
 */
package de.gee.erep.client.ui.view;

import java.util.ArrayList;

import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

import de.gee.erep.client.ui.displays.CountryDisplay;
import de.gee.erep.shared.entities.Country;

/**
 * @author Matthew Gee created: 13.03.2011
 */
public class CountryView implements CountryDisplay {
	/***/
	private CellTable<Country> cellTable;

	/**
	 * 
	 */
	public CountryView() {
		cellTable = new CellTable<Country>();
		configureTable();
		cellTable.setStyleName("cellTable");
	}

	/**
	 */
	private void configureTable() {
		TextColumn<Country> first = new TextColumn<Country>() {
			@Override
			public String getValue(final Country c) {
				return String.valueOf(c.getId());
			}
		};
		cellTable.addColumn(first, "ID");
		TextColumn<Country> sec = new TextColumn<Country>() {
			@Override
			public String getValue(final Country c) {
				return c.getName();
			}
		};
		cellTable.addColumn(sec, "Name");
		TextColumn<Country> third = new TextColumn<Country>() {
			@Override
			public String getValue(final Country c) {
				return String.valueOf(c.getCitizenCount());
			}
		};
		cellTable.addColumn(third, "Cit_Count");
		TextColumn<Country> fourth = new TextColumn<Country>() {
			@Override
			public String getValue(final Country c) {
				return String.valueOf(c.getAverageCitizenLevel());
			}
		};
		cellTable.addColumn(fourth, "AVG_Cit_Level");
		TextColumn<Country> fifth = new TextColumn<Country>() {
			@Override
			public String getValue(final Country c) {
				return String.valueOf(c.getRegionCount());
			}
		};
		cellTable.addColumn(fifth, "Region_Count");
	}

	/**
	 * @param list l
	 */
	@Override
	public final void setData(final ArrayList<Country> list) {
		cellTable.setRowData(list);
	}
	
	@Override
	public final Widget asWidget() {
		return cellTable.asWidget();
	}
}
